--提示管理类
--
--
local Marquee = class("Marquee")
function Marquee:ctor()
	
end
function Marquee:show(str)
	local target = display.newScale9Sprite(mgrs.res:getPngPath("HintBack"));
	target:setContentSize(cc.size(800,56));
	local size = target:getContentSize();
	local dis = 100;
	local rect = cc.rect(dis,0,size.width-dis*2,size.height);
	local clippingNode = display.newClippingRectangleNode(rect);
	target:addChild(clippingNode);
	target:setPosition(cc.p(568,580));
	local lbl = cc.ui.UILabel.new({UILabelType = 2, text = str, size = 32});	
	lbl:setAnchorPoint(cc.p(0,0.5));
	lbl:setPosition(cc.p(rect.width + dis,rect.height/2));
	clippingNode:addChild(lbl);
	mgrs.wnd:getLayer(enums.Layer.Tips):addChild(target);
	
	local speed = 80;
	local len = lbl:getContentSize().width;
	local total = rect.width + len;
	
	mgrs.action:beginAction(lbl):MoveBy(total/speed,cc.p(-total,	0)):CallFunc(function()
		mgrs.action:beginAction(target):FadeOut(0.5):CallFunc(function()
			target:removeFromParent(true);
			mgrs.hint:startShowBulletin(1);
		end):endAction();
	end):endAction();
end


local Hint = class("Hint");
function Hint:ctor()
	self.str = "";
end
function Hint:show(str)
    self.str = str;
	local baseSize = cc.size(300,50);
	local length = 0;
	local height = 0;
	local target = display.newScale9Sprite(mgrs.res:getPngPath("noticeBg"));	
	local lbl = cc.ui.UILabel.new({UILabelType = 2, text = str, size = 32});	
	local lblSize = lbl:getContentSize();
	lbl:setColor(cc.c3b(0,255,0));
	lblSize.width = lblSize.width + 100;
	length = lblSize.width;
	if lblSize.width <= baseSize.width then
		length = baseSize.width;
	end
	
	if lblSize.height <= baseSize.height then
		height = baseSize.height;
	end
	target:setContentSize(cc.size(length,height));
	lbl:setAnchorPoint(cc.p(0.5,0.5));
	lbl:setPosition(cc.p(length/2,height/2));
	target:addChild(lbl);		
	target:setPosition(cc.p(display.cx,display.cy - 50));
	mgrs.wnd:getLayer(enums.Layer.Tips):addChild(target);
	target:setOpacity(1);
	local t = 0.5;
	target:setCascadeOpacityEnabled(true);
	mgrs.action:beginAction(target):FadeTo(t,255):MoveBy(t,cc.p(0,50)):Spawn(2):DelayTime(t):FadeTo(t,0):MoveBy(t,cc.p(0,50)):Spawn(2):CallFunc(function()
		target:removeFromParent(true);
        self.str = "";
		mgrs.hint:startShowHint(0.25);
	end):endAction();
	
end



local HintMgr = class("HintMgr");
function HintMgr:ctor()
    self.marquee = nil;
	self.hint = nil;
end

function HintMgr:showBulletin(str)
--	handler(str,handler(self,self.test))();
	if self.marquee == nil then
		self.marquee = Marquee.new();
	end
	mgrs.behave:addBehave(handler(str,handler(self.marquee,self.marquee.show)),enums.Behave.Bulletin);
end

function HintMgr:showHint(str)
    if self.hint and self.hint.str == str then
        return;
    end
    if self.hint == nil then
		self.hint = Hint.new();
	end
	mgrs.behave:addBehave(handler(str,handler(self.hint,self.hint.show)),enums.Behave.Hint);
end

function HintMgr:startShowHint(s)
	-- body
	mgrs.behave:nextBehave(enums.Behave.Hint,s); 
end

function HintMgr:startShowBulletin(s)
	-- body
	mgrs.behave:nextBehave(enums.Behave.Bulletin,s); 
end


mgrs.hint = nil;
mgrs.singleClass(mgrs,HintMgr,"hint");


--endregion
